package com.small.nacos.naming.consistency.ephemeral.distro.component;

import com.small.nacos.core.cluster.ServerMemberManager;
import com.small.nacos.core.distributed.distro.component.DistroTransportAgent;
import com.small.nacos.core.distributed.distro.entity.DistroData;
import com.small.nacos.naming.misc.NamingProxy;

/**
 * @Author zhoujin
 * @Date 2022/11/13 17:06
 */
public class DistroHttpAgent implements DistroTransportAgent {

    private final ServerMemberManager memberManager;

    public DistroHttpAgent(ServerMemberManager memberManager) {
        this.memberManager = memberManager;
    }

    @Override
    public boolean syncData(DistroData data, String targetServer) {
        if (!memberManager.hasMember(targetServer)) {
            return true;
        }
        byte[] dataContent = data.getContent();
        return NamingProxy.syncData(dataContent, data.getDistroKey().getTargetServer());
    }
}
